import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Gys} from "../model/admin/Gys";
import {ReferType} from "../model/admin/ReferType";
import {ReferData} from "../model/admin/ReferData";
import {Cargocate} from "../model/admin/Cargocate";
import {CoffeIncoming} from "../model/CoffeIncoming";
import {Materiaincoming} from "../model/materiaincoming";
import {BakeProPlan} from "../model/ProPlan";
import {Dbd} from "../model/Dbd";
import {BakeRecord} from "../model/BakeRecord";
import {BakeTestRecord} from "../model/BakeTestRecord";
import {BakeBeanSort} from "../model/BakeBeanSort";
import {BakeCupTest} from "../model/BakeCupTest";
import {Encapsulation} from "../model/Encapsulation";
import {Prohouseid} from "../model/Prohouseid";
import {Prodoutbound} from "../model/Prodoutbound";
import {HostService} from "./host.service";

@Injectable({
  providedIn: 'root'
})
export class AdminService {
  public Host_Admin =this.host.HOST+ "/coffeemanagement/"

  constructor(private http: HttpClient,
              private host :HostService) {
  }

  private getReferdataSelectByTypeidURL = this.Host_Admin + "member/getReferdataSelectByTypeid";

  getReferdataSelectByTypeid(id: string) {
    let parm = {
      "typeid": id
    }
    return this.http.post(this.getReferdataSelectByTypeidURL, parm).toPromise()
  }

  private getNzSelCateByTypeidURL = this.Host_Admin + "member/getNzSelCateByTypeid";

  getNzSelCateByTypeid(id: string) {
    let parm = {
      "cargocateid": id
    }
    return this.http.post(this.getNzSelCateByTypeidURL, parm).toPromise()
  }

  private getNztreeCargocateURL = this.Host_Admin + "member/getNztreeCargocate";

  getNztreeCargocate() {
    return this.http.get(this.getNztreeCargocateURL).toPromise();
  }

  private saveGysURL = this.Host_Admin + "member/saveGys";

  saveGys(g: Gys) {
    return this.http.post(this.saveGysURL, g).toPromise();
  }

  private getGysesURL = this.Host_Admin + "member/getGyses";

  getGyses() {
    return this.http.get(this.getGysesURL).toPromise()
  }

  private deleteGysByidURL = this.Host_Admin + "member/deleteGysByid";

  deleteGysByid(id: string) {
    let parm = {
      "gysid": id
    }
    return this.http.post(this.deleteGysByidURL, parm).toPromise();
  }

  private getGysByidURL = this.Host_Admin + "member/getGysByid";

  getGysByid(id: string) {
    let parm = {
      "gysid": id
    }
    return this.http.post(this.getGysByidURL, parm).toPromise();
  }

  private getRefertypesURL = this.Host_Admin + "member/getRefertypes";

  getRefertypes() {
    return this.http.get(this.getRefertypesURL).toPromise();
  }

  private getRefertypebyidURL = this.Host_Admin + "member/getRefertypebyid";

  getRefertypebyid(id: string) {
    let parm = {
      "refertypeid": id
    }
    return this.http.post(this.getRefertypebyidURL, parm).toPromise();
  }

  private saveRefertypeURL = this.Host_Admin + "member/saveRefertype";

  saveRefertype(r: ReferType) {
    return this.http.post(this.saveRefertypeURL, r).toPromise();
  }

  private deleteRefertypebyidURL = this.Host_Admin + "member/deleteRefertypebyid";

  deleteRefertypebyid(id: string) {
    let parm = {
      "refertypeid": id
    }
    return this.http.post(this.deleteRefertypebyidURL, parm).toPromise();
  }

  private getReferdatasByTypeidURL = this.Host_Admin + "member/getReferdatasByTypeid";

  getReferdatasByTypeid(id: string) {
    let parm = {
      "typeid": id
    }
    return this.http.post(this.getReferdatasByTypeidURL, parm).toPromise()
  }

  private saveReferdataURL = this.Host_Admin + "member/saveReferdata";

  saveReferdata(r: ReferData) {
    return this.http.post(this.saveReferdataURL, r).toPromise()
  }

  private getReferdatabyidURL = this.Host_Admin + "member/getReferdatabyid";

  getReferdatabyid(id: string) {
    let parm = {
      "referdata": id
    }
    return this.http.post(this.getReferdatabyidURL, parm).toPromise()
  }

  private deleteReferdatabyidURL = this.Host_Admin + "member/deleteReferdatabyid";

  deleteReferdatabyid(id: string) {
    let parm = {
      "referdata": id
    }
    return this.http.post(this.deleteReferdatabyidURL, parm).toPromise()
  }

  private saveCargocateURL = this.Host_Admin + "member/saveCargocate";

  saveCargocate(c: Cargocate) {
    return this.http.post(this.saveCargocateURL, c).toPromise()
  }

  private deleteCargocateURL = this.Host_Admin + "member/deleteCargocate";

  deleteCargocate(id: string) {
    let parm = {
      "cargocateid": id
    }
    return this.http.post(this.deleteCargocateURL, parm).toPromise()
  }

  private getCargocateByidURL = this.Host_Admin + "member/getCargocateByid";

  getCargocateByid(id: string) {
    let parm = {
      "cargocateid": id
    }
    return this.http.post(this.getCargocateByidURL, parm).toPromise()
  }

  private deleteCoffeeincomingByidURL = this.Host_Admin + "member/deleteCoffeeincomingByid";

  deleteCoffeeincomingByid(id: string) {
    let parm = {
      "incomingid": id
    }
    return this.http.post(this.deleteCoffeeincomingByidURL, parm).toPromise()
  }

  private getCoffeeincomingByidURL = this.Host_Admin + "member/getCoffeeincomingByid";

  getCoffeeincomingByid(id: string) {
    let parm = {
      "incomingid": id
    }
    return this.http.post(this.getCoffeeincomingByidURL, parm).toPromise()
  }

  private saveCoffeeincomingURL = this.Host_Admin + "member/saveCoffeeincoming";

  saveCoffeeincoming(c: CoffeIncoming) {

    return this.http.post(this.saveCoffeeincomingURL, c).toPromise()
  }

  private getCoffeeincomingsURL = this.Host_Admin + "member/getCoffeeincomings";

  getCoffeeincomings() {
    return this.http.get(this.getCoffeeincomingsURL).toPromise();
  }

  private getGysSelURL = this.Host_Admin + "member/getGysSel";

  getGysSel() {
    return this.http.get(this.getGysSelURL).toPromise();
  }

  private saveMatincomingURL = this.Host_Admin + "member/saveMatincoming";

  saveMatincoming(m: Materiaincoming) {
    return this.http.post(this.saveMatincomingURL, m).toPromise();
  }

  private deleteMatincomingbyidURL = this.Host_Admin + "member/deleteMatincomingbyid";

  deleteMatincomingbyid(m: string) {
    let parm = {
      "matariaincomingid": m
    }
    return this.http.post(this.deleteMatincomingbyidURL, parm).toPromise();
  }

  private getMatincomingbyidURL = this.Host_Admin + "member/getMatincomingbyid";

  getMatincomingbyid(m: string) {
    let parm = {
      "matariaincomingid": m
    }
    return this.http.post(this.getMatincomingbyidURL, parm).toPromise();
  }

  private getMatincomingsURL = this.Host_Admin + "member/getMatincomings";

  getMatincomings() {
    return this.http.get(this.getMatincomingsURL).toPromise();
  }

  private getProplansURL = this.Host_Admin + "member/getProplans";

  getProplans() {
    return this.http.get(this.getProplansURL).toPromise()
  }

  private deleteProplanByidURL = this.Host_Admin + "member/deleteProplanByid";

  deleteProplanByid(id: string) {
    let parm = {
      "proplanid": id
    }
    return this.http.post(this.deleteProplanByidURL, parm).toPromise()
  }

  private getProplanByidURL = this.Host_Admin + "member/getProplanByid";

  getProplanByid(id: string) {
    let parm = {
      "proplanid": id
    }
    return this.http.post(this.getProplanByidURL, parm).toPromise()
  }

  private saveProplanURL = this.Host_Admin + "member/saveProplan";

  saveProplan(p: BakeProPlan) {

    return this.http.post(this.saveProplanURL, p).toPromise()
  }

  private saveDbdURL = this.Host_Admin + "member/saveDbd";

  saveDbd(o: Dbd) {
    return this.http.post(this.saveDbdURL, o).toPromise()
  }

  private deleteDbdByidURL = this.Host_Admin + "member/deleteDbdByid";

  deleteDbdByid(id: string) {
    let parm = {
      "dbdid": id
    }
    return this.http.post(this.deleteDbdByidURL, parm).toPromise()
  }

  private getDbdByidURL = this.Host_Admin + "member/getDbdByid";

  getDbdByid(id: string) {
    let parm = {
      "dbdid": id
    }
    return this.http.post(this.getDbdByidURL, parm).toPromise()
  }

private getNzCoffeeincomingsByPmURL = this.Host_Admin+"member/getNzCoffeeincomingsByPm";
  getNzCoffeeincomingsByPm(id:string){
    let parm ={
      "pm":id
    }
    return this.http.post(this.getNzCoffeeincomingsByPmURL,parm).toPromise()
  }
private getCoffeeNumByPmURL = this.Host_Admin+"member/getCoffeeNumByPm";
  getCoffeeNumByPm(id:string){
    let parm ={
      "pm":id
    }
    return this.http.post(this.getCoffeeNumByPmURL,parm).toPromise()
  }
  private getMateriainventoryByPmURL = this.Host_Admin+"member/getMateriainventoryByPm";
  getMateriainventoryByPm(id:string){
    let parm ={
      "pm":id
    }
    return this.http.post(this.getMateriainventoryByPmURL,parm).toPromise()
  }
  private getNzMatincomingsByPmURL = this.Host_Admin+"member/getNzMatincomingsByPm";
  getNzMatincomingsByPm(id:string){
    let parm ={
      "pm":id
    }
    return this.http.post(this.getNzMatincomingsByPmURL,parm).toPromise()
  }

  private getDbdsURL = this.Host_Admin + "member/getDbds";

  getDbds() {
    return this.http.get(this.getDbdsURL).toPromise()
  }
  private getDbdsByClqkURL = this.Host_Admin + "member/getDbdsByClqk";

  getDbdsByClqk(id:string) {
    let parm = {
      "clqk":id
    }
    return this.http.post(this.getDbdsByClqkURL,parm).toPromise()
  }

  private getBakerecordURL = this.Host_Admin + "member/getBakerecord";

  getBakerecord() {
    return this.http.get(this.getBakerecordURL).toPromise()
  }

  private getBakerecordsByClqkURL = this.Host_Admin + "member/getBakerecordsByClqk";

  getBakerecordsByClqk(c: string) {
    let parm = {
      "clqk": c
    }
    return this.http.post(this.getBakerecordsByClqkURL, parm).toPromise()
  }

  private saveBakerecordURL = this.Host_Admin + "member/saveBakerecord";

  saveBakerecord(b: BakeRecord) {
    return this.http.post(this.saveBakerecordURL, b).toPromise()
  }

  private deleteBakerecordByidURL = this.Host_Admin + "member/deleteBakerecordByid";

  deleteBakerecordByid(id: string) {
    let parm = {
      "bakerecordid": id
    }
    return this.http.post(this.deleteBakerecordByidURL, parm).toPromise();
  }

  private getBakerecordByidURL = this.Host_Admin + "member/getBakerecordByid";

  getBakerecordByid(id: string) {
    let parm = {
      "bakerecordid": id
    }
    return this.http.post(this.getBakerecordByidURL, parm).toPromise();
  }

  private getBakeTestRecordURL = this.Host_Admin + "member/getBaketests";

  getBakeTestRecords() {
    return this.http.get(this.getBakeTestRecordURL).toPromise()
  }

  private getBaketestsByClqkURL = this.Host_Admin + "member/getBaketestsByClqk";

  getBaketestsByClqk(v: string) {
    let parm = {
      "clqk": v
    }
    return this.http.post(this.getBaketestsByClqkURL, parm).toPromise()
  }

  private saveBaketestURL = this.Host_Admin + "member/saveBaketest";

  saveBaketest(b: BakeTestRecord) {
    return this.http.post(this.saveBaketestURL, b).toPromise()
  }

  private deleteBakeTestRecordByidURL = this.Host_Admin + "member/deleteBaketestByid";

  deleteBakeTestRecordByid(id: string) {
    let parm = {
      "baketestid": id
    }
    return this.http.post(this.deleteBakeTestRecordByidURL, parm).toPromise();
  }

  private getBakeTestRecordByidURL = this.Host_Admin + "member/getBaketestByid";

  getBakeTestRecordByid(id: string) {
    let parm = {
      "baketestid": id
    }
    return this.http.post(this.getBakeTestRecordByidURL, parm).toPromise();
  }


  private getEncapsortsURL = this.Host_Admin + "member/getEncapsorts";

  getEncapsorts() {
    return this.http.get(this.getEncapsortsURL).toPromise()
  }

  private saveEncapsortURL = this.Host_Admin + "member/saveEncapsort";

  saveEncapsort(b: BakeBeanSort) {
    return this.http.post(this.saveEncapsortURL, b).toPromise()
  }

  private deleteEncapsortByidURL = this.Host_Admin + "member/deleteEncapsortByid";

  deleteEncapsortByid(id: string) {
    let parm = {
      "encapsortid": id
    }
    return this.http.post(this.deleteEncapsortByidURL, parm).toPromise();
  }

  private getEncapsortByidURL = this.Host_Admin + "member/getEncapsortByid";

  getEncapsortByid(id: string) {
    let parm = {
      "encapsortid": id
    }
    return this.http.post(this.getEncapsortByidURL, parm).toPromise();
  }

  private getEncapsortByClqkURL = this.Host_Admin + "member/getEncapsortByClqk";

  getEncapsortByClqk(c: string) {
    let parm = {
      "clqk": c
    }
    return this.http.post(this.getEncapsortByClqkURL, parm).toPromise()
  }

  private getCuptestByClqkURL = this.Host_Admin + "member/getCuptestByClqk";

  getCuptestByClqk(c: string) {
    let parm = {
      "clqk": c
    }
    return this.http.post(this.getCuptestByClqkURL, parm).toPromise()
  }

  private getCuptestByidURL = this.Host_Admin + "member/getCuptestByid";

  getCuptestByid(id: string) {
    let parm = {
      "cuptestid": id
    }
    return this.http.post(this.getCuptestByidURL, parm).toPromise()
  }

  private deleteCuptestByidURL = this.Host_Admin + "member/deleteCuptestByid";

  deleteCuptestByid(id: string) {
    let parm = {
      "cuptestid": id
    }
    return this.http.post(this.deleteCuptestByidURL, parm).toPromise()
  }

  private saveCuptestURL = this.Host_Admin + "member/saveCuptest";

  saveCuptest(id: BakeCupTest) {

    return this.http.post(this.saveCuptestURL, id).toPromise()
  }

  private getCuptestsURL = this.Host_Admin + "member/getCuptests";

  getCuptests() {
    return this.http.get(this.getCuptestsURL).toPromise();
  }

  private deleteEncapsulationByidURL= this.Host_Admin+"member/deleteEncapsulationByid";
  deleteEncapsulationByid(id:string){
    let parm = {
      "encapsulationid":id
    }
    return this.http.post(this.deleteEncapsulationByidURL,parm).toPromise()
  }

  private getEncapsulationByidURL= this.Host_Admin+"member/getEncapsulationByid";
  getEncapsulationByid(id:string){
    let parm = {
      "encapsulationid":id
    }
    return this.http.post(this.getEncapsulationByidURL,parm).toPromise()
  }
  private getEncapsulationsByClqkURL= this.Host_Admin+"member/getEncapsulationsByClqk";
  getEncapsulationsByClqk(id:string){
    let parm = {
      "clqk":id
    }
    return this.http.post(this.getEncapsulationsByClqkURL,parm).toPromise()
  }

  private saveEncapsulationURL= this.Host_Admin+"member/saveEncapsulation";
  saveEncapsulation(parm:Encapsulation){

    return this.http.post(this.saveEncapsulationURL,parm).toPromise()
  }

  private getEncapsulationsURL= this.Host_Admin+"member/getEncapsulations";
  getEncapsulations(){
    return this.http.get(this.getEncapsulationsURL).toPromise()
  }

  private getProhouseidsURL = this.Host_Admin+"member/getProhouseids";
  getProhouseids(){
    return this.http.get(this.getProhouseidsURL).toPromise()
  }

  private deleteProhouseidByidURL = this.Host_Admin+"member/deleteProhouseidByid";
  deleteProhouseidByid(id:string){
    let parm = {
      "prohouseid":id
    }
    return this.http.post(this.deleteProhouseidByidURL,parm).toPromise()
  }
  private getProhouseidByidURL = this.Host_Admin+"member/getProhouseidByid";
  getProhouseidByid(id:string){
    let parm = {
      "prohouseid":id
    }
    return this.http.post(this.getProhouseidByidURL,parm).toPromise()
  }
  private getProhouseidByClqkURL = this.Host_Admin+"member/getProhouseidByClqk";
  getProhouseidByClqk(id:string){
    let parm = {
      "clqk":id
    }
    return this.http.post(this.getProhouseidByClqkURL,parm).toPromise()
  }
  private saveProhouseidURL = this.Host_Admin+"member/saveProhouseid";
  saveProhouseid(parm:Prohouseid){

    return this.http.post(this.saveProhouseidURL,parm).toPromise()
  }
private deleteProdoutboundByidURL = this.Host_Admin+"member/deleteProdoutboundByid";
  deleteProdoutboundByid(id:string){
    let param =  {
      "prodoutboundid":id
    }
    return this.http.post(this.deleteProdoutboundByidURL,param).toPromise()
  }
  private getProdoutboundByidURL = this.Host_Admin+"member/getProdoutboundByid";
  getProdoutboundByid(id:string){
    let param =  {
      "prodoutboundid":id
    }
    return this.http.post(this.getProdoutboundByidURL,param).toPromise()
  }
  private saveProdoutboundURL = this.Host_Admin+"member/saveProdoutbound";
  saveProdoutbound(param:Prodoutbound){

    return this.http.post(this.saveProdoutboundURL,param).toPromise()
  }
  private getProdoutboundsURL = this.Host_Admin+"member/getProdoutbounds";
  getProdoutbounds( ){

    return this.http.get(this.getProdoutboundsURL).toPromise()
  }

  private getKcslByProidURL = this.Host_Admin+"member/getKcslByProid";
  getKcslByProid(id:string){
    let parm = {
      "proid":id
    }
    return this.http.post(this.getKcslByProidURL,parm).toPromise()
  }

  private getRawBeanNumURL=this.Host_Admin+"member/getRawBeanNum";
  getRawBeanNum(){
    return  this.http.get(this.getRawBeanNumURL).toPromise();
  }
 private getKcslsURL=this.Host_Admin+"member/getKcsls";
  getKcsls(){
    return  this.http.get(this.getKcslsURL).toPromise();
  }


  private getRawBeanInventoryChangeListURL=this.Host_Admin+"member/getRawBeanInventoryChangeList";
  getRawBeanInventoryChangeList(){
    return this.http.get(this.getRawBeanInventoryChangeListURL).toPromise();
  }
  private getMateriaInventoryChangeListURL=this.Host_Admin+"member/getMateriaInventoryChangeList";
  getMateriaInventoryChangeList(){
    return this.http.get(this.getMateriaInventoryChangeListURL).toPromise();
  }

  private getMateriaStaticNumURL=this.Host_Admin+"member/getMateriaStaticNum";
  getMateriaStaticNum(){
    return this.http.get(this.getMateriaStaticNumURL).toPromise();
  }

  private getTicketUEL = this.Host_Admin+"member/getTicket";
  getTicket(){
    return this.http.get(this.getTicketUEL).toPromise()
  }
  private generateBcodeUEL = this.Host_Admin+"member/generateBcode";
  generateBcode(id:string){
    let parm = {
      "encapsulationid":id
    }
    return this.http.post(this.generateBcodeUEL,parm).toPromise()
  }

  private downLoadFormFileFor2017XLSURL=this.Host_Admin+"member/downLoadFormFile";
  downLoadFormFileFor2017XLS(filename:string){
    let parm={
      "parm":filename
    }

    return this.http.post(this.downLoadFormFileFor2017XLSURL,parm,{responseType:'blob' as 'json'}).subscribe(
      (response:any)=>{
        let dataType = response.type;
        let binaryData = [];
        binaryData.push(response);
        let downloadLink = document.createElement('a');
        downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, {type: dataType}));
        downloadLink.download=filename
        //downloadLink.setAttribute('download', );
        downloadLink.setAttribute('target','_blank')
        document.body.appendChild(downloadLink);
        downloadLink.click();


      }
    )
  }
  private getBlockChainDbsURL = this.Host_Admin+"member/getBlockChainDbs";
  getBlockChainDbs(){
    return this.http.get(this.getBlockChainDbsURL).toPromise()
  }

  private getLoginlogsURL = this.Host_Admin+"member/getLoginlogs";
  getLoginlogs(){
    return this.http.get(this.getLoginlogsURL).toPromise()
  }

  private getSearchlogsURL = this.Host_Admin+"member/getSearchlogs";
  getSearchlogs(){
    return this.http.get(this.getSearchlogsURL).toPromise()
  }
}

